package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.controller.demo.domain.SysWarehouse;
import com.ruoyi.web.controller.service.ISysWarehouseService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * sys_warehouseController
 * 
 * @author ruoyi
 * @date 2022-12-30
 */
@Controller
@RequestMapping("/system/warehouse")
public class SysWarehouseController extends BaseController
{
    private String prefix = "system/warehouse";

    @Autowired
    private ISysWarehouseService sysWarehouseService;

    @RequiresPermissions("system:warehouse:view")
    @GetMapping()
    public String warehouse()
    {
        return prefix + "/warehouse";
    }

    /**
     * 查询sys_warehouse列表
     */
    @RequiresPermissions("system:warehouse:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysWarehouse sysWarehouse)
    {
        startPage();
        List<SysWarehouse> list = sysWarehouseService.selectSysWarehouseList(sysWarehouse);
        return getDataTable(list);
    }

    /**
     * 导出sys_warehouse列表
     */
    @RequiresPermissions("system:warehouse:export")
    @Log(title = "sys_warehouse", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysWarehouse sysWarehouse)
    {
        List<SysWarehouse> list = sysWarehouseService.selectSysWarehouseList(sysWarehouse);
        ExcelUtil<SysWarehouse> util = new ExcelUtil<SysWarehouse>(SysWarehouse.class);
        return util.exportExcel(list, "sys_warehouse数据");
    }

    /**
     * 新增sys_warehouse
     */
    @GetMapping("/add")
    public String add(Model model)

    {
        SysUser sysUser = getSysUser();
        model.addAttribute("user", sysUser);
        return prefix + "/add";
    }

    /**
     * 新增保存sys_warehouse
     */
    @RequiresPermissions("system:warehouse:add")
    @Log(title = "sys_warehouse", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysWarehouse sysWarehouse)
    {
        return toAjax(sysWarehouseService.insertSysWarehouse(sysWarehouse));
    }

    /**
     * 修改sys_warehouse
     */
    @RequiresPermissions("system:warehouse:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysUser sysUser = getSysUser();
        mmap.put("user", sysUser);
        SysWarehouse sysWarehouse = sysWarehouseService.selectSysWarehouseById(id);
        mmap.put("sysWarehouse", sysWarehouse);
        return prefix + "/edit";
    }

    /**
     * 修改保存sys_warehouse
     */
    @RequiresPermissions("system:warehouse:edit")
    @Log(title = "sys_warehouse", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysWarehouse sysWarehouse)
    {
        return toAjax(sysWarehouseService.updateSysWarehouse(sysWarehouse));
    }

    /**
     * 删除sys_warehouse
     */
    @RequiresPermissions("system:warehouse:remove")
    @Log(title = "sys_warehouse", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysWarehouseService.deleteSysWarehouseByIds(ids));
    }
}
